#include "minIni.h"
#include <stdio.h>

#define SIZE 128

typedef struct
{
    char id[SIZE];
    char type[SIZE];
    char interface_name[SIZE];
    char wake_on_lan[SIZE];
    char ipv4_method[SIZE];
    char ipv4_dns[SIZE];
    char ipv6_method[SIZE];
} configuration;

int main()
{
    configuration config;
    const char *filename = "./netplan-eth1.nmconnection";

    ini_gets("connection", "id", "", config.id, SIZE, filename);
    ini_gets("connection", "type", "", config.type, SIZE, filename);
    ini_gets("connection", "interface-name", "", config.interface_name, SIZE, filename);
    ini_gets("ethernet", "wake-on-lan", "", config.wake_on_lan, SIZE, filename);
    ini_gets("ipv4", "method", "", config.ipv4_method, SIZE, filename);
    ini_gets("ipv4", "dns", "", config.ipv4_dns, SIZE, filename);
    ini_gets("ipv6", "method", "", config.ipv6_method, SIZE, filename);

    printf("Config loaded from %s: id=%s, type=%s, interface-name=%s, wake-on-lan=%s, ipv4_method=%s, ipv4_dns=%s, ipv6_method=%s\n",
           filename, config.id, config.type, config.interface_name, config.wake_on_lan, config.ipv4_method, config.ipv4_dns, config.ipv6_method);


    filename = "/tmp/eth1.nmconnection";
    ini_puts("connection", "id", config.id, filename);
    ini_puts("connection", "type", config.type, filename);
    ini_puts("connection", "interface-name", config.interface_name, filename);
    ini_puts("ethernet", "wake-on-lan", config.wake_on_lan, filename);
    ini_puts("ipv4", "method", config.ipv4_method, filename);
    ini_puts("ipv4", "dns", config.ipv4_dns, filename);
    ini_puts("ipv6", "method", config.ipv6_method, filename);
    printf("Config written to %s\n", filename);

    return 0;
}
